import random

import pystache
import time


class Utils:

    STR_FORMAT_1 ='%Y-%m-%d'
    STR_FORMAT_2 = '%Y-%m-%d %H:%M:%S'
    STR_FORMAT_3 = '%Y/%m/%d'
    STR_FORMAT_4 = '%Y/%m/%d %H:%M:%S'

    @classmethod
    def parse(cls, template_path, dict):
        # 获取json模板
        template = "".join(open(template_path, encoding='UTF-8').readlines())
        return pystache.render(template, dict)

    @classmethod
    def udid(cls):
        # 取当前时间戳，小数点替换为空，取11位
        return str(time.time()).replace(".", "")[0:11]

    @classmethod
    def time_add_day(cls,day=1,format = STR_FORMAT_1):
        #'%Y-%m-%d %H:%M:%S'
        import datetime
        now = datetime.datetime.now()
        date = now + datetime.timedelta(days=day)
        return datetime.datetime.strftime(date, format)

    @classmethod
    def time_add_month(cls, month=1):
        import datetime
        from dateutil.relativedelta import relativedelta
        return str(datetime.date.today() + relativedelta(months=+month, days=-1))

    @classmethod
    def cur_time(cls,format = STR_FORMAT_2):
        import datetime
        now = datetime.datetime.now()
        return datetime.datetime.strftime(now, format)

    @classmethod
    def create_random_plate(cls):
        list = ["京","津","沪","渝","冀","豫","云","辽","黑","湘","皖","鲁","新","苏","浙","赣","鄂","桂","甘","晋","蒙","陕","吉","闽","贵","粤","青","藏","川","宁","琼","台","军","港","澳","使"]
        letter = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
        plateNo = random.choice(list)+random.choice(letter)+str(random.randint(0,9))+random.choice(letter)+str(random.randint(000,999))
        return plateNo


